<?php
/**
* function.php file
* create by ljanson
* @2013-3-6
*/
//数据清理函数
function clean($data)
{
	if(is_array($data))
	{
		foreach($data as $key=>$value)
		{
			if(is_array($value))
			{
				$clean[$key] = clean($value);
			}
			else
			{
				$clean[$key] = addslashes(htmlspecialchars(trim($value)));
			}
		}
	}
	else
	{
		$clean = addslashes(htmlspecialchars(trim($data)));
	}
	return $clean;
}

//获取远程IP函数
function GetIP(){
	if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown'))
	{
		$userip = getenv('HTTP_CLIENT_IP');
	}
	elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown'))
	{
		$userip = getenv('HTTP_X_FORWARDED_FOR');
	}
	elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown'))
	{
		$userip = getenv('REMOTE_ADDR');
	}
	elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown'))
	{
		$userip = $_SERVER['REMOTE_ADDR'];
	}
	return $userip;
}
